/**
 * chenuu.com
 * 
 * @author  zhaoxu.com@gmail.com
 * @created 2012-11-18
 */
package com.chenuu.webapp.document.store;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chenuu.webapp.document.domain.DropboxFileGroup;
import com.chenuu.webapp.document.domain.DuplicateFiles;
import com.chenuu.webapp.document.repository.DuplicateFilesRepository;

/**
 *
 */
@Service("documentStore")
public class DocumentStoreImpl implements DocumentStore {

	@Autowired
	private DuplicateFilesRepository duplicateFilesRepository;
	
	@Override
	public void saveUserDuplicateFiles(String accessKey, List<DropboxFileGroup> groupList) {
		duplicateFilesRepository.delete(accessKey);
		Date now = new Date();
		DuplicateFiles d = new DuplicateFiles();
		d.setGroupList(groupList);
		d.setLastCheck(now);
		d.setAccessKey(accessKey);
		duplicateFilesRepository.save(d);
	}
	
	@Override
	public DuplicateFiles listUserDuplicateFiles(String userId) {
		return duplicateFilesRepository.findOne(userId);
	}
}
